<template>
	<view class="warp">
		<!-- #ifdef APP-PLUS -->
		<view class="title-contents"><view class="top-view status"></view></view>
		<!-- #endif -->
		<view class="login-title">
			<view class="logo"><image src="/static/images/common/logo.png" mode=""></image></view>
		</view>
		<view class="login-phone form-wapper">
			<view class="phone input-wapper">
				<view class="lside"><text class="iconfont icon-shouji"></text></view>
				<view class="mobile rside"><input placeholder-class="input-placeholder" v-model="username" type="number" placeholder="请输入手机号" /></view>
			</view>
			<view class="code input-wapper">
				<view class="lside"><text class="iconfont icon-mima2"></text></view>
				<view class="rside"><input placeholder-class="input-placeholder" v-model="password" type="password" maxlength="12" placeholder="请输入密码(6-12位) " /></view>
			</view>
			<view class="paw"><view class="btn" @click="navTo('/pages/public/code_login')">验证码登录</view></view>
		</view>

		<button type="primary" class="login-btn" @click="getLogin()">登录</button>
		<view class="reg-paw">
			<text class="active" @click="navTo('/pages/public/reg')">注册账号</text>
			<text @click="navTo('/pages/public/forget')">忘记密码</text>
		</view>
		<!-- #ifdef APP-PLUS -->
		<view class="quick">
			<view class="quick-title">
				<text class="line"></text>
				<text class="txt">快捷登陆</text>
				<text class="line"></text>
			</view>
			<view class="sanfang"><image src="../../static/temp/share_wechat.png" mode=""></image></view>
		</view>
		<!-- #endif -->
	</view>
</template>
<script>
export default {
	data() {
		return {
			username: '',
			password: '',
			uid:''
		};
	},
	methods: {
		getLogin() {
			let {username,password}=this
			uni.$u.http.post('/user/login', {
				username,password
			}).then(res => {
				if (res.code == 0) {
					//登陆成功
					uni.showToast({
						title: '登录成功',
						duration: 2000
					});
					let { uid, token, username, userInfo, tokenExpired } = res;
					//存放本地
					uni.setStorageSync('uid', uid);
					uni.setStorageSync('token', token);
					uni.setStorageSync('username', username);
					uni.setStorageSync('userInfo', userInfo);
					uni.setStorageSync('tokenExpired', tokenExpired);
					//1秒后返回
					setTimeout(v => {
						uni.reLaunch({
							url: '/pages/user/user'
						});
					}, 1000);
				} else if (this.username.length == 0 || this.password.length == 0) {
					uni.showToast({
						title: '用户名/密码不能为空',
						icon: 'none',
						duration: 2000
					});
				} else {
					uni.showToast({
						title: res.errMsg,
						icon: 'none',
						duration: 2000
					});
				}
			});
		}
	}
};
</script>
<style lang="scss">
@import 'login.scss';
</style>
